package com.shsmi.jc.seed.controller.api;

import cn.hutool.json.JSONUtil;
import com.shsmi.jc.seed.common.MyHttpResponse;
import com.shsmi.jc.seed.entity.SystemUser;
import com.shsmi.jc.seed.exception.MyException;
import com.shsmi.jc.seed.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/open")
public class OpenController {

    @Autowired
    private AuthService authService;

    @PostMapping(path = "/user_register")
    @ResponseBody
    MyHttpResponse register(@RequestBody String request) {
        try {

            SystemUser record =  JSONUtil.toBean(request, SystemUser.class);
            return MyHttpResponse.of(true, authService.register(record), null, null);
        } catch (MyException e) {
            return MyHttpResponse.of(false, null, e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            return MyHttpResponse.of(false, null, e.getMessage(), null);
        }
    }
}
